class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  
  before_action :authenticate_user!
  
  
  
  def after_sign_in_path_for(resource)
    if mobile?
      redirect_to openid_index(:token => user_token) 
    else
      home_index_path
    end
  end
  
   MOBILE_USER_AGENTS =  'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
  'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
  'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
  'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
  'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile'

  def mobile?
    agent_str = request.user_agent.to_s.downcase
    # return false if agent_str =~ /ipad/
    return true if agent_str =~ /ipad/
    agent_str =~ Regexp.new(MOBILE_USER_AGENTS)
  end
end
